package com.android_map_app.data;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;

import com.android_map_app.activities.MapApplication;

public class UserData {

	private User user;
	private Map<String, LinkedList<User>> groups;
	private Object groupsLock;
	
	private UserData() {
		user = new User();
		groups = new HashMap<String, LinkedList<User>>();
		groupsLock = new Object();
	}

    private static class SingletonHolder {
            public static final UserData instance = new UserData();
    }

    public static UserData getInstance() {
            return SingletonHolder.instance;
    }

    public LinkedList<User> getActiveGroupMembers() {
    	synchronized (groupsLock) {
			return groups.get(MapApplication.mPrefs.getString("activeGroup", ""));
		}
    }
	public Map<String, LinkedList<User>> getGroups() {
		synchronized (groupsLock) {
			return groups;
		}
	}

	public void setGroups(Map<String, LinkedList<User>> groups) {
		synchronized (groupsLock) {
			this.groups = groups;
		}
	}
	
	public void setUsersToGroup(String group, LinkedList<User> users) {
		synchronized (groupsLock) {
			this.groups.put(group, users);
		}
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}
    
}
